#!/usr/bin/python
import sys , re
sys.path.append("../classes")
from logger import *
from sqlgroup import *
logger = Logger("../logs")
logger.setVerbose()

###################################################################

print "time offset ranges..."

db_conf = {"seconds_offset" : 2 * 24 * 60 * 60 , "seconds_range" : 120 , 'table':'searches_last_30_days' ,
        'host':'redshift01.infra-team.com' , 'port':'5439'  ,'db':'icbi' , 'user':'icbi','password':'UAx9O7kg49:5^Y5' , 'rdbms':'postgresql' ,'time_field':'datetime'}

group_conf = {"fields": ["b","bv","cc"] , "sumfields":{"uid":"dist" , "uage":"avg"} , "minval" : 20 , "splitter":"^^^"}

compare_conf = {"faults_min":5 , "rates" : {"count":0.5 , "uid" : 0.5 , "uage":0.8}}


s = SqlGroup("test",db_conf,group_conf,compare_conf,logger)
s.pulse()

print "monitored ..."

group_conf = {"fields": ["b","bv","cc"] , "sumfields":{"uid":"dist" , "uage":"avg"} , "minval" : 20 , "splitter":"^^^" , "monitor":"true"}

s = SqlGroup("test",db_conf,group_conf,compare_conf,logger)
s.pulse()


print "with filter{p:funmoods} ..."

group_conf = {"fields": ["b","bv","cc"] , "sumfields":{"uid":"dist"} , "minval" : 10 , "splitter":"^^^" , "filter":{"p":"funmoods"}}
s = SqlGroup("test",db_conf,group_conf,compare_conf,logger)
s.pulse()


group_conf = {"fields": ["b","bv","cc"] , "sumfields":{"uid":"dist"} , "minval" : 100 , "splitter":"^^^" , "filter":{"p":"funmoods"}}

print "fix times ..."


db_conf = {"fix_times" : ['2013-12-25','2013-12-25','2013-12-26','2013-12-26'] , 'table':'searches_last_30_days' ,
        'host':'redshift01.infra-team.com' , 'port':'5439'  ,'db':'icbi' , 'user':'icbi','password':'UAx9O7kg49:5^Y5' , 'rdbms':'postgresql' ,'time_field':'datetime'}


s = SqlGroup("test",db_conf,group_conf,compare_conf,logger)
s.pulse()

print "fix times Mysql ..."

compare_conf = {"faults_min":5 , "rates" : {"count":0.9 , "uid" : 0.9 , "uage":0.8}}
group_conf = {"fields": ["b","bv","cc"] , "sumfields":{"uid":"dist"} , "minval" : 5 , "splitter":"^^^" }
db_conf = {"fix_times" : ['2014-01-02 00:00:00','2014-01-02 23:59:59','2014-01-01 00:00:00','2014-01-01 23:59:59'] , 'table':'searches_last_30_days' ,
        'host':'localhost' , 'db':'bi_dev' , 'user':'ohad','password':'ohad1961' , 'rdbms':'mysql' ,'time_field':'datetime'}

s = SqlGroup("test",db_conf,group_conf,compare_conf,logger)
s.pulse()

